package com.simplefaith.delisty.component;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RelativeLayout.LayoutParams;

import com.simplefaith.delisty.R;

public class NoteView extends ImageButton {

	private String noteMessage;
	private boolean isHighLight;

	public void setNoteMessage(String noteMessage) {
		this.noteMessage = noteMessage;
	}

	public String getNoteMessage() {
		return noteMessage;
	}

	private float downRawXOffset, downRawYOffset;

	public NoteView(final Context context, final NoteViewManager noteViewManager) {
		super(context);
		
		this.setLayoutParams(new LayoutParams(200, 140));

		Drawable drawable = context.getResources()
				.getDrawable(R.drawable.noteimage).getConstantState()
				.newDrawable();
		
		this.setBackgroundDrawable(drawable);
		this.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View view, MotionEvent motionEvent) {
				// drag position
				switch (motionEvent.getAction()) {
				case MotionEvent.ACTION_DOWN:
					downRawXOffset = NoteView.this.getX()
							- motionEvent.getRawX();
					downRawYOffset = NoteView.this.getY()
							- motionEvent.getRawY();
					NoteView.this.bringToFront();

					break;
				case MotionEvent.ACTION_MOVE:
					NoteView.this.setX(motionEvent.getRawX() + downRawXOffset);
					NoteView.this.setY(motionEvent.getRawY() + downRawYOffset);
					break;
				case MotionEvent.ACTION_UP:
					break;
				}
				return false;
			}
		});
	}

	@Override
	public void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		if (!isHighLight)
			canvas.drawText("123", 20, 20, new Paint());
	}
}
